// pages/gsyq/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  refresh(){
    wx.showLoading()
    this.onLoad()
    wx.hideLoading()
  },
  copy() {
    wx.setClipboardData({
      data: 'https://pan.baidu.com/s/1AYks8hHk9_8V4qkMQCbvpg ',
      success(res) {
        wx.getClipboardData({
          success(res) {
            wx.showToast({
              title: '内容已复制，请前往浏览器粘贴浏览！',
              icon: 'none',
              duration: 5000
            })
          }
        })
      }
    })
  },

  yes2() {
    var _ = this;
    wx.navigateTo({
      url: '../result/result',
    })
  },
  no2() {
    var _ = this;
    wx.showToast({
      title: '邀请两人才可以领取！',
      icon: 'none'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var _ = this;
    var phone =  wx.getStorageSync('rdjcphone')
    var myavatar =  wx.getStorageSync('myavatar')
    _.setData({
      myavatar
    })
    if(phone){
      wx.request({ //发送请求
        url: "https://zg99.offcn.com/index/kanjia/getxzlist/?actid=50311&callback=?",
        data: {
          phone: wx.getStorageSync('rdjcphone'),
          sstimes: Date.parse(new Date())
        }, //接收参数
        success(res) { //返回
          console.log(res)
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          };
          console.log(theJson.lists)
          _.setData({
            lists: theJson.lists
          })
        }
      })
    } else {
      wx.redirectTo({
        url: '../index/index',
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var _ = this;
    var yqphone = wx.getStorageSync('rdjcphone');
    var isIn = wx.getStorageSync('isIn');
    var area = wx.getStorageSync('area');
    var agent = wx.getStorageSync('agent');
    var page = wx.getStorageSync('page');
    if (!isIn) {
      wx.request({ //发送请求
        url: "https://zg99.offcn.com/index/kanjia/writeyq/?actid=50311&callback=?",
        data: {
          phone: yqphone,
          spid: '1'
        }, //接收参数
        success(res) { //返回
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          };
          console.log(theJson)
          if (theJson.status == 1) {
            wx.setStorageSync('isIn', '1')
          }
        }
      })
    }

    return {
      title: '写作28个热点精粹！',
      path: 'pages/rdjc/index/index?yqphone=' + yqphone + '&area=' + area + '&agent=' + agent + '&page=' + page,
      success: function (res) {
        console.log(res)
      }

    }
  }
})